package mystuff;
import bank.support.*;
import bank.main.*;


import java.io.*;
/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author Mathew Lowery
 * @version 1.0
 */

public class BankApp {
  public static void main(String[] args) throws IOException {
    Bank bank = new Bank(25);
    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));

    while (true) {
      System.out.println("Please make a selection from the following menu.");
      System.out.println("1) open a new bank account");
      System.out.println("2) deposit to a bank account");
      System.out.println("3) withdraw from a bank account");
      System.out.println("4) print short account info");
      System.out.println("5) print detailed account info including "
                         + "last transactions");
      System.out.println("6) quit");
      System.out.print("> ");
      System.out.flush();

      // read input in the form of a String
      String input = stdin.readLine();

      // convert to an int
      int menuChoice = Integer.parseInt(input);

      // find out what user selected

      switch (menuChoice) {
        // open account
        case 1:
        {
          System.out.print("Enter customer name: ");
          System.out.flush();
          String customerName = stdin.readLine();
          System.out.print("Enter opening balance: ");
          System.out.flush();
          input = stdin.readLine();
          double openingBalance = Double.parseDouble(input);
          int newAccountNum = bank.openNewAccount(customerName, openingBalance);
          System.out.println("New account number: " + newAccountNum);
          break;
        }
        // deposit
        case 2:
        {
          System.out.print("Enter account number: ");
          System.out.flush();
          input = stdin.readLine();
          int accountNumber = Integer.parseInt(input);
          System.out.print("Enter amount: ");
          System.out.flush();
          input = stdin.readLine();
          double openingBalance = Double.parseDouble(input);
          bank.depositTo(accountNumber, openingBalance);
          break;
        }
        // withdraw
        case 3:
        {
          System.out.print("Enter account number: ");
          System.out.flush();
          input = stdin.readLine();
          int accountNumber = Integer.parseInt(input);
          System.out.print("Enter amount: ");
          System.out.flush();
          input = stdin.readLine();
          double openingBalance = Double.parseDouble(input);
          bank.withdrawFrom(accountNumber, openingBalance);
          break;
        }
        // print info
        case 4:
        {
          System.out.print("Enter account number: ");
          System.out.flush();
          input = stdin.readLine();
          int accountNumber = Integer.parseInt(input);
          bank.printAccountInfo(accountNumber);
          break;
        }
        // print detailed info
        case 5:
        {
          System.out.print("Enter account number: ");
          System.out.flush();
          input = stdin.readLine();
          int accountNumber = Integer.parseInt(input);
          System.out.print("Enter number of transactions to print: ");
          System.out.flush();
          input = stdin.readLine();
          int lastNTransactions = Integer.parseInt(input);
          bank.printAccountInfo(accountNumber, lastNTransactions);
          break;
        }
        case 6:
        {
          System.exit(0);
        }
        default:
        {
          System.out.println("Unrecognized menu choice.");
          break;
        }
      } // switch
    } // while
  } // main
} // BankApp